from .models import QuestionType,Question,Choice,Answer
from random import sample

#{'选择题'：[5,1],'填空题'：[5,2],...}
#paper_info_obj = {'选择题'：[5,1,[obj]],'填空题'：[5,2,[obj]],...}
#paper_info_pk = {'选择题'：[5,1,[pk,pk]],'填空题'：[5,2],...}
class ProducePaper:
    def __init__(self,info_dict):
        self.info_dict = info_dict
        self.info_dict_obj = self.paper_info_obj()

    def paper_info_obj(self):
        info_dict_obj = self.info_dict.copy()
        for key,value in info_dict_obj.items():            
            qt = QuestionType.objects.get(question_type = key)
            que_all_list = list(qt.question_set.all())
            que_list_obj = sample(que_all_list,value[0])
            #que_list_pk  = [question.id for question in que_list_obj]
            value.append(que_list_obj)
        return info_dict_obj
    
    @property
    def info_dict_pk(self):
        
        #info_dict_pk = self.info_dict_obj.copy()
        info_dict_pk = {}
        for key,value in self.info_dict_obj.items():
            info_dict_pk[key] = value[:]
            info_dict_pk[key][2] = [question.id for question in value[2]]

        return info_dict_pk



    

    

















    
            
        
    
    
